package cn.snews.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import news.News;
import news.topic;
import dao.NewsDAO;
import dao.TopicDAO;

public class ModifyServlet extends HttpServlet {

	private static final long serialVersionUID = 7694077924905898990L;

	public ModifyServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Integer nid = Integer.parseInt(request.getParameter("nid"));
		Integer ntid = Integer.parseInt(request.getParameter("ntid"));
		List<topic> lis = TopicDAO.showAll();
		News news = NewsDAO.showNews(nid);
		request.setAttribute("news", news);
		request.setAttribute("lis", lis);
		request.setAttribute("ntid", ntid);
		request.getRequestDispatcher("/WEB-INF/jsp/modifynews.jsp").forward(
				request, response);
	}

	public void init() throws ServletException {
	}

}
